package logic

import (
	"bw-renting/house-rpc/house"
	"bw-renting/house-rpc/internal/svc"
	"bw-renting/model/mysql"
	"context"
	"strconv"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseLogic {
	return &CreateHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// TODO: 创建房源
func (l *CreateHouseLogic) CreateHouse(in *house.CreateHouseReq) (*house.Response, error) {
	// todo: add your logic here and delete this line
	h := mysql.House{
		UserId:    in.UserId,
		Title:     in.Title,
		AreaId:    in.AreaId,
		Price:     float64(in.Price),
		Address:   in.Address,
		RoomCount: in.RoomCount,
		Acreage:   in.Acreage,
		Unit:      in.Unit,
		CoverUrl:  in.CoverUrl,
	}
	houses := mysql.CreateHouse(h)
	if houses.ID == 0 {
		return &house.Response{
			Status: strconv.Itoa(int(houses.ID)),
		}, nil
	}
	return &house.Response{
		Status: strconv.Itoa(int(houses.ID)),
	}, nil
}
